<template>

  <div>
    <div style="width: 400px;height: 280px;margin: auto" @keydown.enter="login()">
        <h3 style="color: dodgerblue">e购物</h3>
        用户名：<el-input v-model="loginObj.userName"></el-input>
        密码：<el-input type="password" v-model="loginObj.password"></el-input>
        <el-button type="primary" @click="login()" >登录</el-button>
        <div style="color: red">{{errorInfo}}</div>
      <el-col :span="6"></el-col>
    </div>
  </div>
</template>

<script>
import axios  from "axios";
export default {
  data() {
    return {
      errorInfo:"",
      loginObj:{}
    }
  },
  methods:{
    login(){
      axios.get("/project/user/login",{params:this.loginObj}).then(resp=>{
        let userObj = resp.data;
        if(userObj==''){
          this.errorInfo="密码或用户名不正确";
        }else {
          //在sessionStorage中设置登录用户共享数据
          sessionStorage.setItem("loginUser",JSON.stringify(userObj));
          if(userObj.grade=="顾客"){
            this.$router.push("/shopIndex")
          }
          else if(userObj.grade=="管理员"){
            this.$router.push("/manager")
          }
          else if(userObj.grade=="送货员"){
            this.$router.push("/send")
          }
        }
      })
    }
  }
}
</script>

<style scoped>

</style>